const BASE_URL = "http://localhost:3000";
 function request (options) {
  return new Promise((resolve, reject) => {
    uni.request({
      url: BASE_URL + options.url,
      method: options.method || "GET",
      data: options.data || {},
      success: (res) => {
        if (res.statusCode === 200) {
          //请求成功
          resolve(res.data);
        } else if (res.statusCode === 401) {
          uni.showToast({
            icon: "none",
            title: "未登录或登录状态已超时",
            duration: 1500,
          });
        } else if (res.statusCode === 405) {
          uni.showToast({
            icon: "none",
            title: "请求方法错误",
            duration: 1500,
          });
        } else {
          uni.showToast({
            icon: "none",
            title: "请求错误：" + res.statusCode,
            duration: 1500,
          });
        }
      },
      fail: (err) => {
        console.log("err:", err);
        uni.showToast({
          icon: "none",
          title: '服务器出现错误',
          duration: 1500,
        });
        reject(err);
      },
    });
  });
};
export default {request}

